package service

import (
	"blog_go/internal/model"
	"blog_go/internal/repository"
	"errors"
)

type CollectionService interface {
	QueryCollection(userId int) ([]*model.Collection, error)
	AddCollection(collection model.Collection) error
	UpdateCollection(collection model.Collection) error
	DelCollection(collectionId int) error
}

type collectionService struct {
	*Service
	collectionRepo repository.CollectionRepository
}

func NewCollectionService(service *Service, collectionRepo repository.CollectionRepository) CollectionService {
	return &collectionService{
		Service:        service,
		collectionRepo: collectionRepo,
	}
}

// 查询收藏夹
func (s *collectionService) QueryCollection(userId int) ([]*model.Collection, error) {
	if userId == 0 {
		return nil, errors.New("参数错误")
	}

	return s.collectionRepo.QueryCollection(userId)
}

// 添加收藏夹
func (s *collectionService) AddCollection(collection model.Collection) error {
	if collection.UserId == 0 {
		return errors.New("参数错误")
	}

	return s.collectionRepo.AddCollection(collection)
}

// 更新收藏夹
func (s *collectionService) UpdateCollection(collection model.Collection) error {
	if collection.CollectionId == 0 {
		return errors.New("参数错误")
	}

	return s.collectionRepo.UpdateCollection(collection)
}

// 删除收藏夹
func (s *collectionService) DelCollection(collectionId int) error {
	if collectionId == 0 {
		return errors.New("参数错误")
	}

	return s.collectionRepo.DelCollection(collectionId)
}
